package com.wang.ddp.utils;

import cn.hutool.core.bean.BeanUtil;
import com.wang.ddp.dto.UserDTO;
import com.wang.ddp.entity.User;
import org.apache.logging.log4j.util.Strings;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @author wjh
 * @create 2023-04-19
 */
public class LoginInterceptor implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //从ThreadLocal获取用户信息，如果不存在，拦截
        if (UserHolder.getUser() == null){
            response.setStatus(401);
            return false;
        }
        //如果存在就放行
        return true;
    }
}
